Click here to return to the VHDL Reference Guide. |
Access Type | (last edit: 12. January 2023) | |||||||||
Definition | |||||||||||
A data type which allows for dynamic memory allocation, equivalent to pointers in C or Pascal. Used to model large memories. The type Line in package TEXTIO is an access type. An incomplete type declaration is used to permit recursively defined data structures, e.g. linked lists. | |||||||||||
Syntax | |||||||||||
type NewName is access DataType; type IncompleteTypeName;For a complete description please see: Language Reference Manual IEEE 1076-1993, ยง 3.3. |
|||||||||||
Placement | |||||||||||
The Access Type can be placed at the below shown locations.
|
|||||||||||
Rules | |||||||||||
Only variables can be of access type, and they must point to a value allocated dynamically using new (not to another variable). An access variable is initialised to the value null. A procedure DEALLOCATE(Ptr) is implicitly defined and can be called to release the storage allocated using new. |
|||||||||||
Things to remember | |||||||||||
VHDL suffers from dangling pointers. If you copy a pointer then deallocate the memory, the copied pointer still points to the now deallocated location. | |||||||||||
Synthesis | |||||||||||
Not synthesizable. | |||||||||||
Tips | |||||||||||
Can be used to reduce the amount of memory needed to simulate a large memory by only allocating host computer memory when needed. | |||||||||||
Example | |||||||||||
type Link; -- Incomplete type declaration type Item is record Data: Std_logic_vector(7 downto 0); NextItem: Link; end record; type Link is access Item; variable StartOfList, Ptr: Link; -- Add item to start of list Ptr := new Item; -- Allocate storage Ptr.Data := "01010101"; Ptr.NextItem := StartOfList; -- Link item into list StartOfList := Ptr; -- Delete entire list while StartOfList /= null loop Ptr := StartOfList.NextItem; DEALLOCATE(StartOfList); StartOfList := Ptr; end loop; |
|||||||||||
See Also | |||||||||||
New, Type, Null, Record |